<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="组名">
              <j-depart-select v-model="queryParam.EXTRA_DATA_orgCode"></j-depart-select>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="姓名">
              <a-input placeholder="请输入姓名或首字母" v-model="queryParam.firstLetter"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="身份证">
                <a-input placeholder="请输入身份证" v-model="queryParam.idcard"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="户主编码">
                <a-input placeholder="请输入户主编码" v-model="queryParam.farmCode"></a-input>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleGen" type="primary" icon="plus">生成</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('vca_farmland_fee')">导出</a-button>
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
    </div>

    <!-- table区域-begin -->
    <div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">


        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handlePrint(record)">打印</a>
              </a-menu-item>
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <vca-farmland-fee-modal ref="modalForm" @ok="modalFormOk"></vca-farmland-fee-modal>
    <vca-print-village-receipt ref="printModalForm" ></vca-print-village-receipt>

    <j-modal
      title="数据生成"
      :width="400"
      :visible="genButtonVisible"
      @cancel="genButtonVisible=false"
      class="j-super-query-modal"
      style="top:5%;max-height: 95%;"
    >
      <div>覆盖：重新生成数据</div>
      <div>更新：不改变农户编号对应的已收费用、状态和备注</div>
      <template slot="footer">
        <a-button :loading="loading" @click="genButtonVisible=false">关闭</a-button>
        <a-button :loading="loading" type="primary" @click="genData(2)">覆盖</a-button>
        <a-button :loading="loading" type="primary" @click="genData(3)">更新</a-button>
      </template>
    </j-modal>
  </a-card>

</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import VcaFarmlandFeeModal from './modules/VcaFarmlandFeeModal'
  import JDepartSelect from '@/components/jeecg/JDepartSelect'
  import { getAction, httpAction } from '@api/manage'
  import { filterDictText, initDictOptions } from '@comp/dict/JDictSelectUtil'
  import VcaPrintVillageReceipt from './modules/VcaPrintVillageReceipt'

  export default {
    name: 'VcaFarmlandFeeList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      VcaFarmlandFeeModal,JDepartSelect,VcaPrintVillageReceipt
    },
    data () {
      return {
        description: 'vca_farmland_fee管理页面',
        genButtonVisible:false,
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'年度',
            align:"center",
            dataIndex: 'year'
          },
          {
            title:'农户编码',
            align:"center",
            dataIndex: 'farmCode'
          },
          {
            title:'姓名',
            align:"center",
            dataIndex: 'farmName'
          },
          {
            title:'身份证',
            align:"center",
            dataIndex: 'idcard'
          },
          {
            title:'耕地面积',
            align:"center",
            dataIndex: 'tillageArea'
          },
          {
            title:'水费',
            align:"center",
            dataIndex: 'waterFee',
            customRender:function (text,record) {
              return record["receiveWaterFee"]+"/"+text;
            },
            customCell:(record, rowIndex)=>{		//在此处定义
              return this.cellColor(record["waterFee"],record["receiveWaterFee"]);
            }
          },
          {
            title:'保险',
            align:"center",
            dataIndex: 'insuranceFee',
            customRender:function (text,record) {
              return record["receiveInsuranceFee"]+"/"+text;
            },
            customCell:(record, rowIndex)=>{		//在此处定义
              return this.cellColor(record["insuranceFee"],record["receiveInsuranceFee"]);
            }
          },
          {
            title:'服务费',
            align:"center",
            dataIndex: 'serveFee',
            customRender:function (text,record) {
              return record["receiveServeFee"]+"/"+text;
            },
            customCell:(record, rowIndex)=>{		//在此处定义
              return this.cellColor(record["serveFee"],record["receiveServeFee"]);
            }
          }, {
            title:'总计',
            align:"center",
            dataIndex: 'id',
            customRender:function (text,record) {
              return (record["receiveInsuranceFee"]+record["receiveWaterFee"]+record["receiveServeFee"]).toFixed(2)
                +"/"+
                +(record["insuranceFee"]+record["waterFee"]+record["serveFee"]).toFixed(2);
            }
          },
          {
            title:'状态',
            align:"center",
            dataIndex: 'status',
            customRender: (text, record, index) => {
              return filterDictText(this.typeDictOptions, text);
            }
          },
          {
            title:'备注',
            align:"center",
            dataIndex: 'remark'
          },
          {
            title:'组名',
            align:"center",
            dataIndex: 'groupName'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/villageCadreAssist/vcaFarmlandFee/list",
          delete: "/villageCadreAssist/vcaFarmlandFee/delete",
          genData: "/villageCadreAssist/vcaFarmlandFee/genData",
          deleteBatch: "/villageCadreAssist/vcaFarmlandFee/deleteBatch",
          exportXlsUrl: "/villageCadreAssist/vcaFarmlandFee/exportXls",
        },
        dictOptions:{},
        feeDictOptions:[],
        superFieldList:[],
        isorter:{
          column: 'farmCode',
          order: 'asc',
        }
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
        initDictOptions('fee_status').then((res) => {
          if (res.success) {
            this.typeDictOptions = res.result;
          }
        });
        initDictOptions('farmland_fee').then((res) => {
          if (res.success) {
            this.feeDictOptions = res.result;
          }
        });
      },
      cellColor(v,rv){
        if(v==rv){
          return {style:{'color': '#0f0'}}
        }else if(v>rv && rv==0){
          return {style:{'color': '#f00'}}
        }else if(v>rv && rv>0){
          return {style:{'color': '#00f'}}
        }
      },
      genData(type){
        getAction(this.url.genData, {type:type}).then((res)=>{
          if(res.success){
            this.$message.success(res.message);
            this.modalFormOk();
          }else{
            this.$message.warning(res.message);
          }
        }).finally(() => {
          this.genButtonVisible = false;
        })
      },
      handleGen(){
        this.genButtonVisible=true;
      },
      handlePrint(record){
        this.$refs.printModalForm.view(record,this.feeDictOptions);
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'int',value:'year',text:'年度',dictCode:''})
        fieldList.push({type:'string',value:'farmCode',text:'农户编码',dictCode:''})
        fieldList.push({type:'string',value:'farmName',text:'姓名',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'tillageArea',text:'耕地面积',dictCode:''})
        fieldList.push({type:'string',value:'groupName',text:'组名',dictCode:''})
        fieldList.push({type:'int',value:'status',text:'状态'})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>